﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC_Project.Model;
using MVC_Project.Bll.Systems;
using System.Dynamic;
using Newtonsoft.Json;

namespace MVC_Project.UI.Controllers
{
    [CheckLogin]
    public class ManageController : Controller
    {
        // GET: Manage
        public ActionResult Index()
        {
            MenusBll mbll = new MenusBll();
            int rid = (int)Session["rid"];
            var mlist = mbll.GetMenusByRid(rid);
            ViewBag.menus = mlist;


            return View();
        }
        public ActionResult Personal()
        {
            int uid = (int)Session["uid"];

            UsersBll ubll = new UsersBll();

            var user = ubll.GetUsersById(uid);

            return View(user);
        }

        [HttpPost]
        public ActionResult ChangeHeadImg(int imgID)
        {
            int uid = (int)Session["uid"];

            UsersBll ubll = new UsersBll();

            var user = ubll.GetUsersById(uid);
            user.imgID = imgID;

            int num = ubll.Update(user);

            dynamic d = new ExpandoObject();
            if (num > 0)
            {
                d.code = num;
                d.msg = "头像修改成功！";
            }
            else {
                d.code = num;
                d.msg = "头像修改失败！";
            }

            return Content(JsonConvert.SerializeObject(d), "application/json");
          


        }
        

    }
}